<script>
import {mapState} from "vuex";

export default {
  name: "scrollMenu",
  data() {
    return {}
  },
  props: {
    height: {
      type: String,
      default: ""
    },
    scrollY: {
      type: Boolean,
      default: true
    },
    cateList: {
      type: Array,
      default: () => ([])
    }
  },
  computed: {
    ...mapState("categoryStore", ["cat_id"])
  },
  methods: {
    handleChangeActive(id) {
      this.$store.commit("categoryStore/changeCateId", id)
      this.$store.commit("categoryStore/changeScrollTop", Math.random())
    }
  },
}
</script>

<template>
  <scroll-view class="scrollMenu" :style="{height}" :scroll-y="scrollY">
    <view v-for="(cate1,index) in cateList" :key="cate1.cat_id" :class="{active:cate1.cat_id===cat_id}" @click="handleChangeActive(cate1.cat_id)">{{ cate1.cat_name }}</view>
  </scroll-view>
</template>

<style scoped lang="scss">
.scrollMenu {
  width: 100%;
  height: 100%;
  background-color: #f7f7f7;

  view {
    width: 100%;
    height: 100rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-size: 26rpx;

    &.active {
      background-color: #ffffff;
      color: #c00000;
      display: flex;
      align-items: center;

      &::before {
        content: "";
        display: block;
        width: 6rpx;
        height: 60rpx;
        background-color: #c00000;
        position: absolute;
        left: 0;
      }
    }
  }
}
</style>
